package com.ruoyi.jproom.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.jproom.entity.Housing;
import com.ruoyi.jproom.service.HousingManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author zeo
 * @explain 房源管理
 * @date 2020/8/7 11:14
 */
@Controller
@RequestMapping("/housingManage")
public class HousingManageController extends BaseController {

    @Autowired
    HousingManageService housingManageService;

    private String prefix = "housingmanage";

    /**
     * 跳转出租房源管理界面
     * @return
     */
    @GetMapping("/toRentHousingManage")
    public String toRentHousingManage() {
        return prefix + "/rentHousingManage";
    }

    /**
     * 获取出租房源数据
     * @param housing
     * @return
     */
    @RequestMapping("/findRentHousingList")
    @ResponseBody
    public TableDataInfo findRentHousingList(Housing housing){
        return getDataTable(housingManageService.findRentHousingList(housing));
    }

    /**
     * 跳转出售房源管理界面
     * @return
     */
    @GetMapping("/toSellHousingManage")
    public String toSellHousingManage() {
        return prefix + "/sellHousingManage";
    }

    /**
     * 获取出租房源数据
     * @param housing
     * @return
     */
    @RequestMapping("/findSellHousingList")
    @ResponseBody
    public TableDataInfo findSellHousingList(Housing housing){
        return getDataTable(housingManageService.findSellHousingList(housing));
    }

    /**
     * 修改房源数据
     * @param id
     * @param mmap
     * @return
     */
    @GetMapping("/rentHousingEdit/{id}")
    public String rentHousingEdit(@PathVariable("id") String id, ModelMap mmap,int type) {
        Housing housing = housingManageService.findHousingByHousingId(id);
        mmap.put("housing",housing);
        if(type == 0){
            return prefix + "/rentHousingEdit";
        }else{
            return prefix + "/sellHousingEdit";
        }
    }


    @RequestMapping("/rentHousingEdit")
    @ResponseBody
    public AjaxResult rentHousingEdit(Housing housing){
        return toAjax(housingManageService.rentHousingEdit(housing));
    }


    @RequestMapping("/toVoidHousing")
    @ResponseBody
    public AjaxResult toVoidHousing(String housingId){
        return toAjax(housingManageService.toVoidHousing(housingId));
    }


}
